<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>相册管理</title>
<link rel="stylesheet" href="/networkforum/css/user_info.css" />
<link rel="stylesheet" href="/networkforum/css/user_control_group.css" />
<!–[if lt IE9]> 
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]–>
<script type="text/javascript">
window.onload = function(){
	getGroups("picture",pgOption);
}
var pgOption={
	'pictureSrc':{
		'param':{
			'id':"pictureSrc",
			'onclick':groupHandle
		},
		'bind':{
			'module':"picture",
			'groupId':"groupId",
			'groupName':"groupName",
			'number':"number",
			'isPublic':"isPublic",
			'password':"password"
		}
	},
	'groupName':{
		'param':{
			'id':"groupName"
		}
	}
}
var agOption={
	'groupName':{
		'param':{
			'id':"groupName",'onclick':groupHandle
		},
		'bind':{
			'module':"article",
			'groupId':"groupId",
			'groupName':"groupName",
			'number':"number",
			'isPublic':"isPublic",
			'password':"password"
		},
		'style':{
			'cursor':"pointer"
		}
	}
}
function getGroups(moduleName,option){
	var myajax = getByAjax();
	myajax.init(null,"get",true);
	myajax.get("/networkforum/group/get_groups.do?moduleName="+encodeURIComponent(moduleName),function(d){
		//var data = eval("("+d+")");
		var data = toJson(d);
		page.view("ulInner",data,option);
		autoChange();
	});
	myajax = null;
}
function articleGroups(){
	var ulInner = document.getElementById("ulInner");
	var li = document.createElement("li");
	var span = document.createElement("span");
	span.id="groupName";
	li.appendChild(span);
	li.style.display = "none";
	ulInner.innerHTML = "";
	ulInner.appendChild(li);
	getGroups("article",agOption);
}
function pictureGroups(){
	var ulInner = document.getElementById("ulInner");
	var img = document.createElement("img");
	var li = document.createElement("li");
	var span = document.createElement("span");
	img.id ="pictureSrc";
	img.alt="暂无封面";
	span.id="groupName";
	
	li.appendChild(img);
	li.appendChild(span);
	li.style.display = "none";
	ulInner.innerHTML = "";
	ulInner.appendChild(li);
	getGroups("picture",pgOption);
}
function changePassword(state){
	document.getElementById("passwordInfo").style.display = state;
}
function groupHandle(event){
	event = event||window.event;
	var target = event.target;
	changeView(target);
}
function autoChange(){
	document.getElementById("showName").innerHTML = "";
	document.getElementById("showNumber").innerHTML = "";
	document.getElementById("showLevel").innerHTML = "";
	var target = document.getElementById("ulInner").children[1];
	if(!target){
		alert("请选择需要删除的一项");
		return;
	}
	changeView(target.children[0]);
}
function changeView(target){
	document.getElementById("showName").innerHTML = target.groupName;
	document.getElementById("showName").groupId = target.groupId;
	document.getElementById("showName").module = target.module;
	document.getElementById("showNumber").innerHTML = target.number;
	document.getElementById("showLevel").innerHTML = target.isPublic;
}
function savePassword(){
	var group = document.getElementById("showName");
	var groupId = group.groupId;
	if(!groupId){
		alert("请先创建一个分组");
		return;
	}
	var module = group.module;
	var password1 = document.getElementById("password1").value;
	var password2 = document.getElementById("password2").value;
	if(password1!=password2){
		alert("两次密码不一致");
		return;
	}
	var myajax = getByAjax();
	myajax.init(null,"get",true);
	myajax.get("/networkforum/group/change_password.do?groupId="+groupId+"&module="+encodeURIComponent(module)+"&password="+password1,function(d){
		//var data = eval("("+d+")");
		var data = toJson(d);
	});
	myajax = null;
	changePassword('none');
	document.getElementById("showLevel").innerHTML = password1==""?"公开":"加密";
}
function deleteGroup(){
	var group = document.getElementById("showName");
	var groupId = group.groupId;
	var module = group.module;
	if(!groupId){
		alert("请选择需要删除的一项");
		return;
	}
	var myajax = getByAjax();
	myajax.init(null,"get",true);
	myajax.get("/networkforum/group/delete_group.do?groupId="+groupId+"&moduleName="+encodeURIComponent(module),function(d){
		//var data = eval("("+d+")");
		var data = toJson(d);
		autoChange();
	});
	myajax = null;

	var ulInner = document.getElementById("ulInner");
	var children = ulInner.children;
	for(var i=1;i<children.length;i++){
		var child = children[i];
		if(child.children[0].groupId==groupId){
			ulInner.removeChild(child);
			break;
		}
	}
	autoChange();
}
</script>
</head>

<body>
	<h2 class="header">分组管理</h2>
	<section class = "groupHeader">
		<span class="group" onclick="pictureGroups();">相册</span>
		<span class="group" onclick="articleGroups();">博客</span>	
	</section>
	<ul class="ulInner" id="ulInner">
		<li>
			<img id="pictureSrc" src="/networkforum/images/left1.jpg" alt="暂无封面"/>
			<span id="groupName">xunxun</span>
		</li>
	</ul>
	<section class="groupInfo">
		<ul id="giInner">
			<li>
				<span>名称：</span><span id="showName">xunxun</span>
			</li>
			<li>
				<span>数量：</span><span id="showNumber">23张</span>
			</li>
			<li>
				<span>状态：</span><span id="showLevel">加密</span>
			</li>
		</ul>	
		<section>
			<span id="changePassword" class="buttom" onclick="changePassword('');">修改密码</span>
			<span id="deleteGroup" class="buttom" onclick="deleteGroup()">删除分组</span>
		</section>	
		<section id="passwordInfo" style="display:none">
			<section>
				<span>密码：</span>
				<input id="password1" type="password" />			
			</section>
			<section>
				<span>确认：</span>
				<input id="password2" type="password" />
			</section>
			<label class="buttom" onclick="savePassword();">保存</label>
			<label class="buttom" onclick="changePassword('none');">取消</label>
		</section>
	</section>
</body>
<script type="text/javascript" src="/networkforum/js/view.js"></script>
<script type="text/javascript" src="/networkforum/js/myajax.js"></script>
<script type="text/javascript" src="/networkforum/js/combo.js"></script>
</html>
